﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;

namespace MicroDalTests
{
    public class TestDbReader : DbDataReader
    {
        private Dictionary<string, object> _backing = new Dictionary<string, object>();

        /// <summary>
        /// Makes datarow with columns.
        /// </summary>
        /// <param name="data">Column1Name, Column1Value, Column2Name, Column2Value,...</param>
        public TestDbReader(params object[] data)
        {
            for (int i = 0; i < data.Length; i += 2)
            {
                var val = data[i + 1];
                if (val is KeyValuePair<Type, DBNull>)
                {

                    _backing.Add(data[i].ToString(), val);
                }
                else
                    _backing.Add(data[i].ToString(), val);
            }
        }

        public override void Close()
        {
            throw new NotImplementedException();
        }

        public override int Depth
        {
            get { throw new NotImplementedException(); }
        }

        public override int FieldCount
        {
            get { return 2; }
        }

        public override bool GetBoolean(int ordinal)
        {
            throw new NotImplementedException();
        }

        public override byte GetByte(int ordinal)
        {
            throw new NotImplementedException();
        }

        public override long GetBytes(int ordinal, long dataOffset, byte[] buffer, int bufferOffset, int length)
        {
            throw new NotImplementedException();
        }

        public override char GetChar(int ordinal)
        {
            throw new NotImplementedException();
        }

        public override long GetChars(int ordinal, long dataOffset, char[] buffer, int bufferOffset, int length)
        {
            throw new NotImplementedException();
        }

        public override string GetDataTypeName(int ordinal)
        {
            throw new NotImplementedException();
        }

        public override DateTime GetDateTime(int ordinal)
        {
            throw new NotImplementedException();
        }

        public override decimal GetDecimal(int ordinal)
        {
            throw new NotImplementedException();
        }

        public override double GetDouble(int ordinal)
        {
            throw new NotImplementedException();
        }

        public override System.Collections.IEnumerator GetEnumerator()
        {
            throw new NotImplementedException();
        }

        public override Type GetFieldType(int ordinal)
        {
            var key = GetName(ordinal);
            return _backing[key].GetType();
        }

        public override float GetFloat(int ordinal)
        {
            throw new NotImplementedException();
        }

        public override Guid GetGuid(int ordinal)
        {
            throw new NotImplementedException();
        }

        public override short GetInt16(int ordinal)
        {
            throw new NotImplementedException();
        }

        public override int GetInt32(int ordinal)
        {
            throw new NotImplementedException();
        }

        public override long GetInt64(int ordinal)
        {
            throw new NotImplementedException();
        }

        public override string GetName(int ordinal)
        {
            int o = 0;
            foreach (var key in _backing.Keys)
            {
                if (o == ordinal)
                    return key;
                o++;
            }
            throw new IndexOutOfRangeException();
        }

        public override int GetOrdinal(string name)
        {
            int o = 0;
            foreach (var key in _backing.Keys)
            {
                if (key == name)
                    return o;
                o++;
            }
            throw new IndexOutOfRangeException(name);
        }

        public override System.Data.DataTable GetSchemaTable()
        {
            throw new NotImplementedException();
        }

        public override string GetString(int ordinal)
        {
            return _backing[GetName(ordinal)] as string;
        }

        public override object GetValue(int ordinal)
        {
            return _backing[GetName(ordinal)];

        }

        public override int GetValues(object[] values)
        {
            throw new NotImplementedException();
        }

        public override bool HasRows
        {
            get { throw new NotImplementedException(); }
        }

        public override bool IsClosed
        {
            get { throw new NotImplementedException(); }
        }

        public override bool IsDBNull(int ordinal)
        {
            return _backing[GetName(ordinal)] == DBNull.Value;
        }

        public override bool NextResult()
        {
            throw new NotImplementedException();
        }

        public override bool Read()
        {
            throw new NotImplementedException();
        }

        public override int RecordsAffected
        {
            get { throw new NotImplementedException(); }
        }

        public override object this[string name]
        {
            get { throw new NotImplementedException(); }
        }

        public override object this[int ordinal]
        {
            get { throw new NotImplementedException(); }
        }
    }
}
